<template>

	<view class="main-tittle acea-row row-between">
		<view class="tittle-left" :style="item.isReward==2?'width:60%':'width: 35%'">
			<text v-if="item.storeCategoryName">{{item.storeCategoryName}}<text
					style="margin: 0 6rpx  ;">|</text></text>{{ item.title }}
		</view>
		<view class="acea-row row-middle row-right">
			<template v-if="item.isReward==2">
				<text class='tittle-right acea-row row-center v' @click="publish "
					style="margin-right: 3px;">发布悬赏</text>
			</template>
			<template v-else>
				<text class='tittle-right acea-row row-center v' @click="publish" style="margin-right: 3px;">修改悬赏</text>
				<template v-if="item.rewardStatus == 1">
					<text class='tittle-right acea-row row-center v' @click="setReward(0)"
						style="margin-right: 3px;">打开悬赏</text>
					<text class='tittle-right acea-row row-center v' v-if="item.trusteeship !='1'" @click="deleteReward"
						style="margin-right: 3px;">删除悬赏</text>
				</template>
				<template v-else>
					<text class='tittle-right acea-row row-center v' @click="setReward(1)"
						style="margin-right: 3px;">关闭悬赏</text>
				</template>
			</template>
			<text class="tittle-right acea-row row-center v" @click="$emit('tgMeth',item.rewardId)"
				v-if="item.isReward == '1' &&item.trusteeship !='1'&&item.rewardStatus != 1">
				立即托管
			</text>

		</view>
	</view>
</template>

<script>
	import {
		closeReward,
		deleteReward
	} from '@/api/api.js'
	export default {
		props: {
			item: {
				type: Object,
				default: () => ({})
			},
			rewardType: {
				type: String | Number,
				default: ""
			}
		},
		data() {
			return {

			}
		},
		methods: {
			publish() {
				// if (this.item.isReward == 1) {
				// 	return;
				// }
				this.item.rewardType = this.rewardType;
				console.log("this.item",this.item)
				let item = JSON.stringify(this.item)
				uni.navigateTo({
					url: '/pages/releases/offeraRreward/offeraRreward?item=' + item
				})
			},
			setReward(st) {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '是否' + (st == 1 ? '关闭' : '打开') + '当前悬赏',
					success: function(res) {
						if (res.confirm) {
							closeReward({
								id: that.item.rewardId,
								status: st
							}).then(res => {
								// that.item. 'rewardStatus' = st;
								that.$emit("updateItem", 'rewardStatus', st)
								that.$util.Tips({
									title: (st == 1 ? '关闭' : '打开') + '悬赏成功'
								})
								// that.item.rewardStatus = st;
							})
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});

			},
			deleteReward() {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '是否删除当前悬赏',
					success: function(res) {
						if (res.confirm) {
							console.log("that.item.rewardId", that.item.rewardId)
							deleteReward(that.item.rewardId).then(res => {
								// that.item. 'rewardStatus' = st;
								that.$emit("updateItem", 'isReward', 2)
								that.$util.Tips({
									title: '删除悬赏成功'
								})
								// that.item.rewardStatus = st;
							})
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	.main-tittle {
		border-bottom: 2rpx solid rgba(238, 238, 238, 1);
		padding: 24rpx 0 18rpx 0;

		.tittle-left {
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
			font-size: 30rpx;
			width: 80%;
			font-weight: 400;
			color: rgba(56, 56, 56, 1);
		}

		.tittle-right {
			// width: 100%;
			line-height: 44rpx;
			padding: 0 14rpx;
			height: 44rpx;
			border-radius: 10rpx;
			background: rgba(238, 33, 45, 1);
			font-size: 24rpx;
			color: rgba(255, 255, 255, 1);
		}
	}
</style>